<template>
  <hips-view sub-header-fixed>
    <hips-nav-bar
      slot="header"
      title="位置信息类"
      :back-button="{
        showLeftArrow: true,
      }"
      @nav-bar-back-click="$router.back()"
    />
    <demo-block title="getCurrentLocation">
      <hips-button @click="getCurrentLocationFuc">
        获取当前位置，单次定位
      </hips-button>
    </demo-block>

    <demo-block title="startContinuousLocation">
      <hips-button @click="startContinuousLocationFuc">
        开始连续定位
      </hips-button>
    </demo-block>

    <demo-block title="stopContinuousLocation">
      <hips-button @click="stopContinuousLocationFuc">
        关闭连续定位
      </hips-button>
    </demo-block>
  </hips-view>
</template>

<script>
import BasicView from '@/mixin/basic-view';
import { Button } from '@hips/vue-ui';

import { Location } from '@hips/plugin-vue-jssdk';

const {
  getCurrentLocation,
  startContinuousLocation,
  stopContinuousLocation,
} = Location;

export default {
  components: {
    [Button.name]: Button,
  },
  mixins: [ BasicView ],
  data() {
    return {};
  },
  methods: {
    getCurrentLocationFuc() {
      getCurrentLocation({ platform: 'baidu' })
        .then((res) => {
          console.log('res = ', res);
        })
        .catch((err) => {
          console.log('err = ', err);
        });
    },

    startContinuousLocationFuc() {
      startContinuousLocation({
        platform: 'baidu',
        onSuccess: (res) => {
          console.log('res = ', res);
        },
        onFail: (err) => {
          console.log('err = ', err);
        },
      });
    },
    stopContinuousLocationFuc() {
      stopContinuousLocation()
        .then((res) => {
          console.log('res = ', res);
        })
        .catch((err) => {
          console.log('err = ', err);
        });
    },
  },
};
</script>

<style lang="stylus"></style>
